import { AxiosRequestConfig } from 'axios';
import request from '@/utils/request';

/**
 * 获取用户列表
 * @param params
 * @returns
 */
export const fetchUsers = (params: any) => {
  return request({
    url: 'system/user/list',
    params,
  });
};

/**创建用户 */
export const createUser = (data: any) => {
  return request({
    url: 'system/user',
    method: 'POST',
    data,
  });
};

/**
 * 删除用户
 * @param id
 * @returns
 */
export const deleteUser = (id: string | number) => {
  return request({
    url: `system/user/${id}`,
    method: 'DELETE',
  });
};

/**
 * 更新用户
 */

export const updateUser = (data: any) => {
  return request({
    url: 'system/user',
    method: 'PUT',
    data,
  });
};

/**
 * 修改用户状态
 * @param data
 * @returns
 */
export function changeUserStatus(data: { userId: string; status: '1' | '0' }) {
  return request({
    url: '/system/user/changeStatus',
    method: 'put',
    data: data,
  });
}

/**
 *  获取用户状态
 * @param data
 * @returns
 */
export function fetchSysNormalDisable() {
  return request<Global.Dict[]>({
    url: 'system/dict/data/type/sys_normal_disable',
  });
}

/**
 * 获取性别
 */
export function fetchGender() {
  return request<Global.Dict[]>({
    url: 'system/dict/data/type/sys_user_sex',
  });
}

/**
 * 获取部门
 */
export const fetchDepartmentApi = () => {
  return request<Global.Department[]>({
    url: 'system/dept/treeselect',
  });
};

/**
 * 获取岗位
 */
export const fetchPost = (userId: string | number = '') => {
  return request<any>({
    url: `system/user/${userId}`,
  });
};

/**
 * 重置密码
 */
export const resetPass = (data: { userId: number; password: string }) => {
  return request({
    url: 'system/user/resetPwd',
    method: 'PUT',
    data,
  });
};

/**
 * 获取角色
 */
export const fetchRoles = (params: any) => {
  return request<Role[]>({
    url: `system/role/list`,
    params,
  });
};

/**
 * 切换角色状态
 */
export const updateRoleStatus = (data: any) => {
  return request({
    url: 'system/role/changeStatus',
    method: 'PUT',
    data,
  });
};

/**
 * 创建角色
 * @returns
 */
export const createRole = (data: Role) => {
  return request({
    url: 'system/role',
    method: 'POST',
    data,
  });
};

/**
 * 获取路由树
 */
export const fetchMenus = () => {
  return request({
    url: 'system/menu/treeselect',
  });
};

/**
 * 删除角色
 */
export const deleteRole = (id: any) => {
  return request({
    url: `/system/role/${id}`,
    method: 'DELETE',
  });
};

/**
 * 获取角色权限
 */
export const fetchRolePermission = (roleId: number) => {
  return request({
    url: `system/menu/roleMenuTreeselect/${roleId}`,
  });
};

/**
 * 获取角色详情
 */
export const fetchRoleInfo = (roleId: number) => {
  return request<Role>({
    url: `system/role/${roleId}`,
  });
};

/**
 * 更新角色
 */
export const updateRole = (data: Role) => {
  return request({
    url: 'system/role',
    method: 'PUT',
    data,
  });
};

/**
 * 获取菜单权限
 */
export const fetchMenusPermission = (params: any) => {
  return request({
    url: 'system/menu/list',
    params,
  });
};

/**
 * 获取菜单详情
 */
export const fetchMenuInfo = (id: number) => {
  return request({
    url: `system/menu/${id}`,
  });
};

/**
 * 创建菜单
 */
export const createMenu = (data: any) => {
  return request({
    url: 'system/menu',
    method: 'POST',
    data,
  });
};

/**
 * 更新菜单
 */
export const updateMenu = (data: any) => {
  return request({
    url: 'system/menu',
    method: 'PUT',
    data,
  });
};

/**
 * 删除菜单
 */
export const deleteMenu = (id: number) => {
  return request({
    url: `system/menu/${id}`,
    method: 'DELETE',
  });
};

/**
 * 字典列表
 */
export const fetchDictList = (params: any) => {
  return request({
    url: 'system/dict/type/list',
    params,
  });
};

/**
 * 新建字典
 */
export const createDict = (data: any) => {
  return request({
    url: 'system/dict/type',
    method: 'POST',
    data,
  });
};

/**
 * 字典修改
 */
export const updateDict = (data: any) => {
  return request({
    url: 'system/dict/type',
    method: 'PUT',
    data,
  });
};

/**
 * 删除字典
 */
export const deleteDict = (ids: number[]) => {
  return request({
    url: `system/dict/type/${ids.join()}`,
    method: 'DELETE',
  });
};

/**
 * 字典详情列表
 */
export const fetchDictDetail = (params: any) => {
  return request({
    url: 'system/dict/data/list',
    params,
  });
};

/**
 * 字典下拉列表
 */
export const fetchDictSelect = () => {
  return request({
    url: 'system/dict/type/optionselect',
  });
};

/**
 * 新增字典 key
 */
export const createDictDetail = (data: any) => {
  return request({
    url: 'system/dict/data',
    method: 'POST',
    data,
  });
};

/**
 * 修改字典 key
 */
export const updateDictDetail = (data: any) => {
  return request({
    url: 'system/dict/data',
    method: 'PUT',
    data,
  });
};

/**
 * 删除字典 key
 */
export const deleteDictDetail = (ids: any) => {
  return request({
    url: `system/dict/data/${ids.join()}`,
    method: 'DELETE',
  });
};

/**
 * 导出字典 key
 */
export const exportDictDetail = (data: any) => {
  return request({
    url: `/system/dict/data/export`,
    method: 'POST',
    responseType: 'blob',
    data,
  });
};

/**
 * 导出字典 key
 */
export const exportDict = (data: any) => {
  return request({
    url: `system/dict/type/export`,
    method: 'POST',
    responseType: 'blob',
    data,
  });
};

/**
 * 参数设置
 */
export const fetchGlobalParams = (params: any) => {
  return request({
    url: 'system/config/list',
    params,
  });
};

/**
 * 新增参数
 */
export const createGlobalParams = (data: any) => {
  return request({
    url: 'system/config',
    method: 'POST',
    data,
  });
};

/**
 * 修改参数
 */
export const updateGlobalParams = (data: any) => {
  return request({
    url: 'system/config',
    method: 'PUT',
    data,
  });
};

/**
 * 删除参数
 */
export const deleteGlobalParams = (ids: number[]) => {
  return request({
    url: `/system/config/${ids.join()}`,
    method: 'DELETE',
  });
};

/**
 * 导出参数
 * @param ids
 * @returns
 */
export const exportGlobalParams = () => {
  return request({
    url: `system/config/export`,
    method: 'POST',
    responseType: 'blob',
  });
};

/**
 * 登录页配置
 */
export const loginPageConfig = () => {
  return request({
    url: '/systemLoginConfig/getInfo',
  });
};

/**
 * 更新登录页配置
 *
 */
export const updateLoginPageConfig = (data: any) => {
  return request({
    url: '/systemLoginConfig/update',
    method: 'PUT',
    data,
  });
};

/**
 * 图片上传
 */
export const uploadImage = (data: any, config: AxiosRequestConfig<any>) => {
  return request({
    url: 'file/uploadImgFile',
    method: 'POST',
    data,
    ...config,
  });
};

/**
 * 更新密码
 */
export const updatePassword = (data: any) => {
  return request({
    url: 'system/user/profile/updatePwd',
    method: 'PUT',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    data,
  });
};

/**
 * 获取用户信息
 */
export const fetchUserInfo = () => {
  return request({
    url: 'system/user/profile',
  });
};

/**
 * 更新用户信息
 */
export const updateUserInfo = (data: any) => {
  return request({
    url: 'system/user/profile',
    method: 'PUT',
    data,
  });
};

/**
 * 部门列表
 */
export const fetchDepartment = (params: any) => {
  return request({
    url: 'system/dept/list',
    params,
  });
};

/**
 * 创建部门
 */
export const createDepartment = (data: any) => {
  return request({
    url: 'system/dept',
    method: 'POST',
    data,
  });
};

/**
 * 创建部门
 */
export const updateDepartment = (data: any) => {
  return request({
    url: 'system/dept',
    method: 'PUT',
    data,
  });
};

/**
 * 创建部门
 */
export const deleteDepartment = (ids: number[]) => {
  return request({
    url: `system/dept/${ids.join()}`,
    method: 'DELETE',
  });
};

// 获取企微绑定用户
export const fetchWeiXinBindUser = (params: any) => {
  return request({
    url: 'qwWeiXin/getBindUser',
    method: 'GET',
    params,
  });
};

// 取消企微绑定
export const cancelBindUser = (data: any) => {
  return request({
    url: 'qwWeiXin/cancelBindUser',
    method: 'POST',
    data,
  });
};

// 生成企微二维码
export const generateWeiXinQrCode = () => {
  return request({
    url: 'qwWeiXin/generate',
    method: 'GET',
  });
};

//
export const bindqwWeiXinUser = (data: any) => {
  return request({
    url: 'qwWeiXin/bindUser',
    method: 'POST',
    data,
  });
};

export const wxUserInfo = (params: any) => {
  return request({
    url: 'qwWeiXin/loginQwOrGetInfo',
    method: 'GET',
    params,
  });
};

/**
 * 用户数据权限
 */
export const fetchUserStationPermission = (userId: string) => {
  return request({
    url: `userStation/getListByUserId/${userId}`,
  });
};

/**
 * 更新用户数据权限
 */
export const updateUserStationPermission = (data: any) => {
  return request({
    url: 'userStation/update',
    method: 'POST',
    data,
  });
};

/**
 * 批量获取字典
 */
export const batchFetchDictionary = (dictTypes: string[]) => {
  return request({
    url: `/system/dict/data/types/${dictTypes.join()}`,
    method: 'GET',
  });
};

/**
 * 关联操作人
 * @param params
 * @returns
 */
export const fetchDeptUser = (params: any) => {
  return request({
    url: 'deptUser/list',
    params,
  });
};

export const addDeptUser = (data: any) => {
  return request({
    url: 'deptUser/add',
    method: 'POST',
    data,
  });
};

export const updateDeptUser = (data: any) => {
  return request({
    url: 'deptUser/update',
    method: 'PUT',
    data,
  });
};

export const deleteDeptUser = (ids: number[]) => {
  return request({
    url: `deptUser/delete/${ids.join()}`,
    method: 'DELETE',
  });
};

export const exportRole = (data: any) => {
  return request({
    url: 'system/role/export',
    method: 'POST',
    responseType: 'blob',
    data,
  });
};

// 查询岗位列表
export function listPost(query: any) {
  return request({
    url: '/system/post/list',
    method: 'get',
    params: query,
  });
}

// 查询岗位详细
export function getPost(postId: any) {
  return request({
    url: '/system/post/' + postId,
    method: 'get',
  });
}

// 新增岗位
export function addPost(data: any) {
  return request({
    url: '/system/post',
    method: 'post',
    data: data,
  });
}

// 修改岗位
export function updatePost(data: any) {
  return request({
    url: '/system/post',
    method: 'put',
    data: data,
  });
}

// 删除岗位
export function delPost(postId: any) {
  return request({
    url: '/system/post/' + postId,
    method: 'delete',
  });
}

export const exportPost = (data: any) => {
  return request({
    url: 'system/post/export',
    method: 'POST',
    responseType: 'blob',
    data,
  });
};

// 查询公告列表
export function listNotice(query: any) {
  return request({
    url: '/system/notice/list',
    method: 'get',
    params: query,
  });
}

// 查询公告详细
export function getNotice(noticeId: any) {
  return request({
    url: '/system/notice/' + noticeId,
    method: 'get',
  });
}

// 新增公告
export function addNotice(data: any) {
  return request({
    url: '/system/notice',
    method: 'post',
    data: data,
  });
}

// 修改公告
export function updateNotice(data: any) {
  return request({
    url: '/system/notice',
    method: 'put',
    data: data,
  });
}

// 删除公告
export function delNotice(noticeId: any) {
  return request({
    url: '/system/notice/' + noticeId,
    method: 'delete',
  });
}

// 清除td数据
export function clearDeviceTdData(data: any) {
  return request({
    url: '/device/clearDeviceTdData',
    method: 'post',
    data,
  });
}
